#!/bin/bash

echo "测试用户注册功能..."
echo "=================="

# 测试注册接口
echo "1. 测试用户注册接口"
curl -X POST http://localhost:8080/api/user/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "test123",
    "confirmPassword": "test123",
    "email": "testuser@example.com",
    "name": "测试用户",
    "age": 25
  }' | jq '.'

echo ""
echo "2. 测试重复用户名注册"
curl -X POST http://localhost:8080/api/user/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "test123",
    "confirmPassword": "test123",
    "email": "testuser2@example.com",
    "name": "测试用户2",
    "age": 26
  }' | jq '.'

echo ""
echo "3. 测试密码不一致"
curl -X POST http://localhost:8080/api/user/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser2",
    "password": "test123",
    "confirmPassword": "test456",
    "email": "testuser2@example.com",
    "name": "测试用户2",
    "age": 26
  }' | jq '.'

echo ""
echo "4. 测试登录新注册的用户"
curl -X POST http://localhost:8080/api/user/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "password": "test123"
  }' | jq '.'

echo ""
echo "测试完成！" 